package com.fs.ibox.web;


import com.fs.ibox.pojo.Carousel;
import com.fs.ibox.service.CarouselService;
import com.fs.ibox.util.BeanFactory;
import com.fs.ibox.util.DateUtil;
import com.fs.ibox.util.ResponseDataUtil;
import com.fs.ibox.util.ResponseJSONUtil;
import com.fs.ibox.vo.ResponseData;


import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.Date;
import java.util.List;

@WebServlet(name = "HomeServlet", value = "/HomeServlet/*")
public class HomeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("application/json;charset=UTF-8");
        String path = request.getPathInfo();
        if("/queryAll".equals(path)){
            queryAll(request,response);
        }

    }

    private void queryAll(HttpServletRequest request, HttpServletResponse response) throws IOException {
        CarouselService bean = BeanFactory.createBean(CarouselService.class);
        List<Carousel> carousels = bean.selectAll();
        ResponseData responseData = ResponseDataUtil.buildOk(carousels);
        ResponseJSONUtil.responseJSON(responseData,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request,response);
    }


}
